//
//  Macro.h
//  TanTanApp
//
//  Created by jutuo on 2017/11/28.
//  Copyright © 2017年 jutuo. All rights reserved.
//

#ifndef Macro_h
#define Macro_h

/***************打印输出*******************/
#ifdef DEBUG
#define CLog(xx, ...)  NSLog(@"%s(%d行):\t\t" xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define CLog(xx, ...)
#endif

/****************系统单例*******************/
#define kUIApplication                  [UIApplication sharedApplication]
#define kUIWindow                       [[kUIApplication delegate] window] //获得window
#define kAppDelegate                    ((AppDelegate *)(kUIApplication.delegate))
#define kUserDefaults                    [NSUserDefaults standardUserDefaults]

/*************获取系统的一些设置************/
/// 系统语言
#define kLanguage_IOS_System ([[NSLocale preferredLanguages] objectAtIndex:0])
/// 当前应用build版本号
#define kApp_Version_Build [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"]
/// 当前应用发布版本号
#define kApp_Version_Short [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"]
// 应用程序的名字
#define kApp_DisplayName  [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]
/*****************系统版本************************/
/// 当前系统版本大于等于某版本
#define IOS_Equal_or_Above(v) (([[[UIDevice currentDevice] systemVersion] floatValue] >= (v))? (YES):(NO))
//大于某版本
#define IOS_Above(v) (([[[UIDevice currentDevice] systemVersion] floatValue] > (v))? (YES):(NO))
/// 当前系统版本小于等于某版本
#define IOS_Equal_or_Below(v) (([[[UIDevice currentDevice] systemVersion] floatValue] <= (v))? (YES):(NO))
//小于某版本
#define IOS_Below(v) (([[[UIDevice currentDevice] systemVersion] floatValue] < (v))? (YES):(NO))
#define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue] == 8 ? (YES):(NO))
#define isIOS9 ([[[UIDevice currentDevice] systemVersion] intValue] == 9 ? (YES):(NO))
#define isIOS10 ([[[UIDevice currentDevice] systemVersion] intValue] == 10 ? (YES):(NO))
#define isIOS11 ([[[UIDevice currentDevice] systemVersion] intValue] == 11 ? (YES):(NO))
#define isIOS12 ([[[UIDevice currentDevice] systemVersion] intValue] == 12 ? (YES):(NO))
#define isIOS13 ([[[UIDevice currentDevice] systemVersion] intValue] == 13 ? (YES):(NO))
#define isIOS14 ([[[UIDevice currentDevice] systemVersion] intValue] == 14 ? (YES):(NO))
/******************iphone 屏幕*********************/
/// 是否是iPad iPhone，和retian屏
#define IS_IPAD ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
#define IS_IPHONE ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

// 屏幕高度、宽度
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height // 主屏幕的高度
#define SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width  // 主屏幕的宽度


#define Screen_Max_Length (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))   // 取屏幕的最大宽度
#define Screen_Min_Length (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))   // 取屏幕的最大宽度

#define Iphone6Width                    375.0
#define kDeviceScaleFactor(num)         ((num) * kDeviceScale)
#define kDeviceScale                    (SCREEN_WIDTH / 375.0)   // 用来适配frame，font等，根据屏幕的大小，适当改变，以iPhone6的宽度为基准
/** 这个参数,看公司项目UI图 具体是哪款机型,默认  iphone6
 RealUISrceenWidth  4/4s 5/5s 320.0  6/6s 375.0  6p/6sp 414.0
 RealUISrceenHeight 4/4s 修改480 5/5s 568.0  6/6s 667.0  6p/6sp 736.0  (备用)
 */
#define kDeviceHeight(h) h * (SCREEN_HEIGHT / 667.0)

/******************iphone型号*********************/
#define is_IPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

//判断iPhone5系列
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)
//判断iPhone6系列
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)
//判断iphone6+系列
#define iPhone7plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)
//判断iPhoneX
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)
//判断iPHoneXr
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)


//判断iPHone11
#define IS_IPHONE11 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

#define IS_IPHONE11_Pro ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

#define IS_IPHONE11_Pro_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

//判断iPhoneXs
#define IS_IPHONE_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

//判断iPhoneXs Max
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

//判断 iphone12 iphone13 iphone12pro iphone13pro
#define IS_IPHONE1213_Or_Pro ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)
//判断iphone12ProMax iphone13ProMax
#define IS_IPHONE1213_Pro_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

#define IS_IPHONE14 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

#define IS_IPHONE14_Pro ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1179, 2556), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

#define IS_IPHONE14_Pro_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1290, 2796), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

#define IS_IPHONE14_Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !is_IPad : NO)

#define APP_STATUSBAR_HEIGHT (CGRectGetHeight([UIApplication sharedApplication].statusBarFrame))

/*******************状态栏高度************************/

// 标准系统状态栏高度
#define SYS_STATUSBAR_HEIGHT ((iPhoneX || IS_IPHONE11_Pro || IS_IPHONE11_Pro_Max ) ? 44.0 : (IS_IPHONE_Xr || IS_IPHONE11) ? 48.0 : (IS_IPHONE1213_Or_Pro || IS_IPHONE1213_Pro_Max || IS_IPHONE14 || IS_IPHONE14_Plus) ? 47 : (IS_IPHONE14_Pro || IS_IPHONE14_Pro_Max) ? 54.0 : 20.0)
// 热点栏高度
#define HOTSPOT_STATUSBAR_HEIGHT 20



// 打开热点
#define IS_HOTSPOT_CONNECTED (APP_STATUSBAR_HEIGHT==(SYS_STATUSBAR_HEIGHT+HOTSPOT_STATUSBAR_HEIGHT)?YES:NO)

#define NavigationBarHeight (SYS_STATUSBAR_HEIGHT + 44.0)
#define OriginY ((self.navBar.hidden == NO) ? NavigationBarHeight : STATUS_BAR_HEIGHT
#define  KSafeBottomMargin  ((iPhoneX || IS_IPHONE11_Pro || IS_IPHONE11_Pro_Max ||IS_IPHONE_Xr || IS_IPHONE11 || IS_IPHONE1213_Or_Pro || IS_IPHONE1213_Pro_Max || IS_IPHONE14 || IS_IPHONE14_Plus || IS_IPHONE14_Pro || IS_IPHONE14_Pro_Max) ? 34.f : 0.f)

#define TabbarHeight ((iPhoneX || IS_IPHONE11_Pro || IS_IPHONE11_Pro_Max ||IS_IPHONE_Xr || IS_IPHONE11 || IS_IPHONE1213_Or_Pro || IS_IPHONE1213_Pro_Max || IS_IPHONE14 || IS_IPHONE14_Plus || IS_IPHONE14_Pro || IS_IPHONE14_Pro_Max)  ? 88.0f : 49.0f)

/*********************颜色************************/
#define UIColorWithRGBHex(rgbValue)     [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define UIColorWithRGBHexA(rgbValue, a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

#define UIColorFromAlphaRGB(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]

#define UIColorWithRGBA(r, g, b, a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]

#define UIColorWithRGB(r, g, b) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1.0]

#define UIColorWithHexString(colorStr) [UIColor colorWithHexString:colorStr]

#define UIColorWithHexStringA(colorStr,a) [UIColor colorWithHexString:colorStr alpha: a]
/*******************字体*********************/
#define UIFontMedium(s)  [UIFont fontWithName:@"PingFangSC-Medium" size:s]
#define UIFontRegular(s)  [UIFont fontWithName:@"PingFangSC-Regular" size:s]
#define UIFontSemibold(s) [UIFont fontWithName:@"PingFangSC-Semibold" size:s]
/*****************加载图片*********************/

#define UIImageLoad(name, type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:name ofType:type]]
#define UIImageNamed( name ) [UIImage imageNamed: name]

/*****************常用文件路径*********************/
#define kPathForDocument NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES)[0]
#define kPathForLibrary  NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSUserDomainMask, YES)[0]
#define kPathForCaches   NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES)[0]

/******************强弱引用***********************/
#define WeakSelf(type) __weak __typeof(type) weak##type = type;
#define StrongSelf(type)  __strong __typeof(type) type = weak##type;
/******************主队列任务***********************/
#define dispatch_sync_main_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}

#define dispatch_async_main_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}

/*****************全局队列任务*****************/
#define dispatch_async_global(identifier,flags,block)\
dispatch_async(dispatch_get_global_queue(identifier, flags), block);

/*******************异步任务*************************/
#define dispatch_async_queue(label,attr,block)\
dispatch_async(dispatch_queue_create(label, attr),block);
// 发送(接受,取消)通知

#define NSNotificationCenterPost(key, obj, info)  [[NSNotificationCenter defaultCenter]postNotificationName:key object:obj userInfo:info];
#define NSNotificationCenterAddObserver(key, function, obj)    [[NSNotificationCenter defaultCenter] addObserver:self selector:NSSelectorFromString(function) name:key object:obj];
#define NSNotificationCenterCanceledAll                   [[NSNotificationCenter defaultCenter] removeObserver:self];
#define NSNotificationCenterCanceled(key, obj) [[NSNotificationCenter defaultCenter]removeObserver:self name:key object:obj];


/****************************flutter method channel*********************************/
#define FlutterChannelName  @"com.xueda.xdzx/channel"
#define FLU_METHOD_OPEN_CLASS_ROOM  @"com.xueda.xdzx/channel/open_class_room"
#define FLU_METHOD_EYE_PROTECTION_MODE @"com.xueda.xdzx/channel/eye_protection_mode"

#endif /* Macro_h */
